package com.mercycrazy.springframework.jdbc.datasource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

/**
 * Helper class that provides static methods for obtaining JDBC Connections from a {@link javax.sql.DataSource}.
 *
 * @author <a href="mailto:1443424326@qq.com">mercycrazy</a>
 * @since 2022-12-04
 */
public abstract class DataSourceUtils {

    public static Connection getConnection(DataSource dataSource) {
        try {
            return dataSource.getConnection();
        } catch (SQLException e) {
            throw new RuntimeException("Failed to obtain JDBC Connection", e);
        }
    }
}
